package com.lkd.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lkd.dto.VmDto;
import com.lkd.entity.VmType;
import com.lkd.mapper.VmTypeMapper;
import com.lkd.result.PageBean;
import com.lkd.service.VmTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VmTypeServiceImpl implements VmTypeService {

    @Autowired
    private VmTypeMapper vmTypeMapper;

    @Override
    public PageBean<VmType> findByPage(VmDto dto) {
        PageHelper.startPage(dto.getPageIndex(),dto.getPageSize());
        List<VmType> list =vmTypeMapper.findByPage(dto);
        Page page =(Page)list;
        PageBean<VmType> vmTypePageBean = new PageBean<>();
        vmTypePageBean.setPageIndex(page.getPageNum());
        vmTypePageBean.setPageSize(page.getPageSize());
        vmTypePageBean.setTotalCount(page.getTotal());
        vmTypePageBean.setTotalPage((long) page.getPages());
        vmTypePageBean.setCurrentPageRecords(page.getResult());
        return vmTypePageBean;

    }

    @Override
    public Boolean addVmType(VmType vmType) {
        return vmTypeMapper.addVmType(vmType);
    }

    @Override
    public Boolean updateVmType(VmType vmType) {
        return vmTypeMapper.updateVmType(vmType);
    }

    @Override
    public Boolean deleteVmType(Integer typeId) {
        return vmTypeMapper.deleteVmType(typeId);
    }
}
